package com.cyber.controller;


import com.cyber.entity.Member;
import com.cyber.entity.Uptime;
import com.cyber.service.IMemberService;
import com.cyber.service.IUptimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmj
 * @since 2022-02-27
 */
@RestController
@RequestMapping("/uptime")
public class UptimeController {
    @Autowired
    private IUptimeService us;
    @Autowired
    private IMemberService ms;
    @GetMapping("/selectAll")
    public List<Uptime> selectAll(Integer cid){
        List<Uptime> list = us.list();
        List<Member> memberList = ms.list();
        list.stream().peek((ut)->{
            Member member = memberList.stream().
                    filter(m -> m.getId() == ut.getUid())
                    .collect(Collectors.toList()).get(0);
            ut.setMember(member);
        }).collect(Collectors.toList());
        return list;
    }
    @PostMapping("/add")
    public void add(@RequestBody Uptime uptime){
        uptime.setCreateTime(LocalDateTime.now());
        us.save(uptime);
    }

}

